<?php  if (!defined('PATH_HD')) exit('No direct script access allowed');

class IndexControl extends Control{
    public $template;
  	function __auto() {
        $template = __ROOT__ . '/template/' . C('style');
        $this->template = PATH_ROOT . '/template/'. C('style');
        $this->assign("template", $template);
        //判断网站是否关闭
        $webtoggle = C("webtoggle");
        if(!$webtoggle){
          header("Content-type:text/html;charset=UTF-8");
          echo "<div style='font:26px/28px 微软雅黑;
          text-align:center;color:#333;border-bottom:solid 1px #eee;
          width:980px;height:30px;
          padding:20px 0px;'>
          :-) 尊敬的用户您好！网站进行系统维护，请您稍后再试，给您带来的不便敬请谅解。</div>";
          die;
        }
      }

    //企业站首页
    function index(){
      $arc = M("image");
      //首页轮播图片
      $arcData = $arc->where('cid=1')->all();
      $mainImgs = array();
      foreach ($arcData as $key=>$value){
        $mainImgs[$key] = $value['thumbimg'];
      } 
      $this->assign("mainImgs",$mainImgs);
      $this->display($this->template . '/index.html');
    }

    //处理列表页模板
    function cat() {
        $cid = intval($_GET['cid']);
        if ($cid) {
            $db = M("category");
            $catData = $db->find($cid);
            //当前栏目信息分配到模板
            $this->assign("field",$catData);
            $this->display($this->template . '/' . $catData['cattpl']);
        } else {
            go(__ROOT__);
        }
    }

    //处理内容页模板
    function arc() {
        $aid = @intval($_GET['aid']);
        if ($aid) {
            C("debug",1);
            $db = M("arc");
            $field = $db->find($aid);
            $cat = $db->table("category")->find($field['cid']);
            $this->assign("field",$field);
            $this->display($this->template . '/' . $cat['arctpl']);
        }
    }

    //用户退出登录
    function logout(){
        session_unset();
        session_destroy();
        go(__ROOT__."/index.php");
    }
}
?>